import { MockMethod } from "vite-plugin-mock";
import FieldVO from "../../src/bean/vo/FieldVO";
import OptionVO from "../../src/bean/vo/OptionVO";

let id = 0;
function getId() {
  return ++id;
}

const priorityOptions: OptionVO[] = [
  {label: "高", value: "high"},
  {label: "中", value: "midden"},
  {label: "低", value: "low"},
];

const data: FieldVO[] = [
  { id: getId(), typeId: 1, name: 'ID', renderType: 'id', displayName: 'ID', requiredRule: 'true', editRule: 'false' },
  { id: getId(), typeId: 1, name: 'Name', renderType: 'text', displayName: '项目名称', requiredRule: 'true', editRule: 'true' },
  { id: getId(), typeId: 1, name: 'Desc', renderType: 'textarea', displayName: '项目简述', requiredRule: 'true', editRule: 'true' },
  { id: getId(), typeId: 1, name: 'Description', renderType: 'rich', displayName: '项目描述', requiredRule: 'true', editRule: 'true' },
  { id: getId(), typeId: 1, name: 'Cycle', renderType: 'number', displayName: '项目周期', requiredRule: 'true', editRule: 'true' },
  { id: getId(), typeId: 1, name: 'Project Start Date', renderType: 'date', displayName: '项目开始时间', requiredRule: 'true', editRule: 'true' },
  { id: getId(), typeId: 1, name: 'Review Date', renderType: 'datetime', displayName: '评审时间', requiredRule: 'true', editRule: 'true' },
  { id: getId(), typeId: 1, name: 'Freeze', renderType: 'boolean', displayName: '是否冻结', requiredRule: 'true', editRule: 'true' },
  { id: getId(), typeId: 1, name: 'Priority', renderType: 'select', displayName: '优先级', requiredRule: 'true', editRule: 'true', options: priorityOptions },
  { id: getId(), typeId: 2, name: 'ID', renderType: 'id', displayName: 'ID', requiredRule: 'true', editRule: 'false' },
  { id: getId(), typeId: 2, name: 'Name', renderType: 'text', displayName: '需求名称', requiredRule: 'true', editRule: 'true' },
  { id: getId(), typeId: 2, name: 'Description', renderType: 'rich', displayName: '需求描述', requiredRule: 'true', editRule: 'true' },
];

export default<MockMethod[]> [
  {
    url: '/api/setting/field/getList',
    method: 'get',
    timeout: 600,
    response: ({ query }) => {
      let results = data;
      if (query?.typeId) {
        results = results.filter(item => item.typeId == query?.typeId);
      }
      return {
        result: true,
        code: 200,
        data: results
      }
    }
  },
  {
    url: '/api/setting/field/save',
    method: 'post',
    timeout: 600,
    response: ({ body }) => {
      return {
        result: true,
        code: 200,
        data: '保存成功'
      }
    }
  },
  {
    url: '/api/setting/field/delete',
    method: 'delete',
    timeout: 600,
    response: ({ body }) => {
      return {
        result: true,
        code: 200,
        data: '删除成功'
      }
    }
  }
]
